package com.lufan.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 视频分辨率枚举类。
 * 更多信息请参考<a href="https://socialsisteryi.github.io/bilibili-API-collect/docs/video/videostream_url.html#qn%E8%A7%86%E9%A2%91%E6%B8%85%E6%99%B0%E5%BA%A6%E6%A0%87%E8%AF%86"></a>
 *
 */
@Getter
public enum VideoResolutionEnum {

    // 通用格式
    RES_240P(6, "240P 极速", false, false, Format.MP4, Platform.HTML5),
    RES_360P(16, "360P 流畅", false, false, Format.MP4),
    RES_480P(32, "480P 清晰", false, false, Format.MP4),
    RES_720P(64, "720P 高清", false, false, Format.MP4, true),
    RES_720P60(74, "720P60 高帧率", true, false, Format.MP4),

    // 登录认证
    RES_1080P(80, "1080P 高清", true, false, Format.MP4, true),
    RES_1080P_PLUS(112, "1080P+ 高码率", true, true, Format.MP4),
    RES_1080P60(116, "1080P60 高帧率", true, true, Format.MP4),

    // DASH格式专属
    RES_4K(120, "4K 超清", true, true, Format.DASH, false, 128),
    RES_HDR(125, "HDR 真彩色", true, true, Format.DASH, false, 64),
    RES_DOLBY_VISION(126, "杜比视界", true, true, Format.DASH, false, 512),
    RES_8K(127, "8K 超高清", true, true, Format.DASH, false, 1024);

    private final Integer qn;
    private final String description;
    private final boolean requireLogin;
    private final boolean requireVip;
    private final Format supportedFormat;
    private final boolean isDefault;
    private final Integer requiredFnval;

    /**
     * 通用构造方法
     */
    VideoResolutionEnum(Integer qn, String description, boolean requireLogin, boolean requireVip,
                        Format supportedFormat, boolean isDefault, Integer requiredFnval) {
        this.qn = qn;
        this.description = description;
        this.requireLogin = requireLogin;
        this.requireVip = requireVip;
        this.supportedFormat = supportedFormat;
        this.isDefault = isDefault;
        this.requiredFnval = requiredFnval;
    }

    // 简化构造方法重载
    VideoResolutionEnum(Integer qn, String description, boolean requireLogin, boolean requireVip, Format format) {
        this(qn, description, requireLogin, requireVip, format, false, null);
    }

    VideoResolutionEnum(Integer qn, String description, boolean requireLogin, boolean requireVip,
                        Format format, boolean isDefault) {
        this(qn, description, requireLogin, requireVip, format, isDefault, null);
    }

    VideoResolutionEnum(Integer qn, String description, boolean requireLogin, boolean requireVip,
                        Format format, Platform platform) {
        this(qn, description, requireLogin, requireVip, format, false, null);

    }

    /**
     * 获取当前登录态可用的清晰度列表
     * @param isLoggedIn 是否登录
     * @param isVip 是否大会员
     * @return 可用清晰度列表
     */
    public static List<VideoResolutionEnum> getAvailableResolutions(boolean isLoggedIn, boolean isVip) {
        return Arrays.stream(values())
                .filter(res -> !res.requireLogin || isLoggedIn)
                .filter(res -> !res.requireVip || (isLoggedIn && isVip))
                .collect(Collectors.toList());
    }


    /**
     * 视频格式枚举
     */
    public enum Format {
        MP4, DASH
    }

    /**
     * 平台限制枚举
     */
    public enum Platform {
        WEB, HTML5, TV, APP
    }


}
